/**
 * Copyright 2008-2009 HAN.BIFANG
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */
package han.bifang.gwt.client.stat.content;

import han.bifang.gwt.client.common.ContentChangeListener;
import han.bifang.gwt.client.common.GwtContext;
import han.bifang.gwt.client.common.entity.StatDetailLog;
import han.bifang.gwt.client.communicate.BifangGWTServiceAsync;
import han.bifang.gwt.client.sec.SecurityConstants;
import han.bifang.gwt.client.stat.StatContentConstants;
import han.bifang.gwt.client.stat.StatMessages;
import han.bifang.gwt.client.stat.content.log.LogDetailContent;
import han.bifang.gwt.client.stat.content.log.LogMgmtContent;

import java.util.HashMap;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;

/**
 * 
 * @Author Kent
 */
public class LogTab extends Composite implements ContentChangeListener {
	private StatMessages cons = null;

	private BifangGWTServiceAsync service = null;

	private GwtContext context = null;

	private SimplePanel panel;

	public LogTab(StatMessages cons, BifangGWTServiceAsync service,
			GwtContext context) {
		this.service = service;
		this.context = context;
		this.cons = cons;

		panel = new SimplePanel();
		
		LogMgmtContent u = new LogMgmtContent(cons,service, context);
		u.setContentChangeListener(this);
		panel.setWidget(u);
		initWidget(panel);

	}

	
	public void onContentChanged(String source, String dest, HashMap props) {
		if (source.equals(StatContentConstants.SEARCH_LOG_PAGE) &&
				dest.equals(StatContentConstants.LOG_DETAIL)) {
			StatDetailLog log = (StatDetailLog)props.get("log");
			context.put(SecurityConstants.SEARCH_PAGE, panel.getWidget());
			LogDetailContent c = new LogDetailContent(cons,service, context,log);
			c.setContentChangeListener(this);
			this.panel.setWidget(c);
			return;
		}else if (source.equals(StatContentConstants.LOG_DETAIL) &&
				dest.equals(StatContentConstants.SEARCH_LOG_PAGE)) {
			
			Widget w = (Widget)context.get(SecurityConstants.SEARCH_PAGE);		
			
			this.panel.setWidget(w);
			return;
		}
	}
}
